{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some Common Modules in Python.\n",
    "\n",
    "### os ,sys ,platform , time ,datetime ,help & dir ,math ,Random ,webbrowser ,calender ."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The os and sys modules provide numerous tools to deal with filenames, paths, directories. The os module contains two sub-modules os.sys (same as sys) and os.path that are dedicated to the system and directories.\n",
    "\n",
    "### We can also use the functions provided by these modules for file, directory, and path manipulations. These modules are wrappers for platform-specific modules, so functions like `os.path.split` work on UNIX, Windows, Mac OS, and any other platform supported by Python.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Os Module & Platform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-31T02:47:50.317538Z",
     "start_time": "2018-08-31T02:47:50.312539Z"
    }
   },
   "outputs": [],
   "source": [
    "# # Importing the operating system module...\n",
    "# \"\"\"\n",
    "# The listdir() function returns the content of a directory. Note, however, that it mixes directories and files.\n",
    "# \"\"\"\n",
    "# import os\n",
    "# import os.path\n",
    "# print(os.name)\n",
    "# print(\"The os.getcwd() returns the CWD Current Working Directory.\\n \",os.getcwd())   # Returns the Current Working Directory.\n",
    "# print()\n",
    "# # printing absolute path\n",
    "# print(\"The os.path.abspath('.') returns the Absolute path of the CWD.\\n \",os.path.abspath('.'))\n",
    "# print()\n",
    "# print(\"The os.listdir('.') returns the list of All the directories present in current directory/Folder \\n \",os.listdir('.'))\n",
    "# print()\n",
    "# print(os.environ)\n",
    "\n",
    "# print()\n",
    "# # Importing the platform  module...\n",
    "# import platform\n",
    "# print(platform.version())\n",
    "# print(platform.system())\n",
    "# print(platform.release())\n",
    "# print(platform.win32_ver())\n",
    "# print(platform.platform())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### According to the [doc](http://docs.python.org/2/library/os.html), os.name currently has one of the following: 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'. What you are after might be sys.platform.\n",
    "\n",
    "#### The os-module lets us run different code dependent on which operating system the code is running on. 'nt' means that you are running windows, and 'posix' mac."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Accessing environment variables\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-30T17:52:00.814861Z",
     "start_time": "2018-08-30T17:52:00.811881Z"
    }
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "and if you know what you are doing, you can add or replace a variable:\n",
    "\"\"\"\n",
    "import os\n",
    "# os.environ.keys()\n",
    "\n",
    "\n",
    "# os.environ[NAME] = VALUE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n",
      "2197\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "os.path provides methods to extract information about path and file names:\n",
    ">>> os.path.curdir # returns the current directory ('.')\n",
    ">>> os.path.isdir(dir) # returns True if dir exists\n",
    ">>> os.path.isfile(file) # returns True if file exists\n",
    ">>> os.path.islink(link) # returns True if link exists\n",
    ">>> os.path.exists(dir) # returns True if dir exists (full pathname or filename)\n",
    ">>> os.path.getsize(filename) # returns size of a file without opening it.\n",
    "\"\"\"\n",
    "\n",
    "import os\n",
    "import os.path\n",
    "print(os.path.isdir(os.getcwd()))\n",
    "print(os.path.isfile(\"common_modules.py\"))\n",
    "print(os.path.exists(os.getcwd()))\n",
    "print(os.path.getsize(\"common_modules.py\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### mkdir() Function & rmdir() function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "The mkdir() function creates a directory.\n",
    "It returns an error if the parent directory does not exist.\n",
    "If you want to create the parent directory as well, you should rather use makedirs():\n",
    "\n",
    "Once created, you can delete an empty directory with rmdir():\n",
    "\n",
    "You can remove all directories within a directory (if there are not empty) by using os.removedirs().\n",
    "If you want to delete a non-empty directory, use shutil.rmtree() (with cautious).\n",
    "\n",
    "To remove a file, use os.remove(). \n",
    "It raise the OSError exception if the file cannot be removed.\n",
    "Under Linux, you can also use os.unlink().\n",
    "\n",
    "\"\"\"\n",
    "import os\n",
    "# os.mkdir('Mukesh') # creates Mukesh directory inside the current directory\n",
    "# os.rmdir('Mukesh') # Removes Mukesh directory inside the current directory\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Removing a file\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "# os.remove('pass file name ')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Renaming files or directories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The dir is: ['.ipynb_checkpoints', 'common_modules.py', 'Some_Common_Modules.ipynb']\n",
      "Successfully renamed.\n",
      "the dir is: ['.ipynb_checkpoints', 'common_modules.py', 'Some_Common_Modules.ipynb']\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "You can rename a file from an old name to a new one by using os.rename(). See also os.renames().\n",
    "os.renames(old, new)\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "\n",
    "import os, sys\n",
    "\n",
    "\n",
    "# os.renames('common_modules.py', 'common_modules_renamed.py')\n",
    "\n",
    "# listing directories\n",
    "print(\"The dir is: %s\" %os.listdir(os.getcwd()))\n",
    "\n",
    "# renaming directory ''tutorialsdir\"\n",
    "# os.rename(\"existingfilename\",\"newfileafterrename_name\")\n",
    "\n",
    "print( \"Successfully renamed.\")\n",
    "\n",
    "# listing directories after renaming \"tutorialsdir\"\n",
    "print(\"the dir is: %s\" %os.listdir(os.getcwd()))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### You can access to the time when a file was last modified. Nevertheless, the output is not friendly user. Under Unix it corresponds to the time since the Jan 1, 1970 (GMT) and under Mac OS since Jan 1, 1904 (GMT)Use the time module to make it easier to read:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1535620776.88\n",
      "Thu Aug 30 14:49:36 2018\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "mtime = os.path.getmtime(\"common_modules.py\") # returns time when the file was last modified\n",
    "print(mtime)\n",
    "\n",
    "\"\"\"\n",
    "The output is not really meaningful since it is expressed in seconds.\n",
    "You can use the time module to get a better layout of that time:\n",
    "\"\"\"\n",
    "\n",
    "print(time.ctime(mtime))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python DateTime, TimeDelta, Strftime(Format) with Examples.\n",
    "\n",
    "In Python, date, time and datetime classes provides a number of function to deal with dates, times and time intervals. Date and datetime are an object in Python, so when you manipulate them, you are actually manipulating objects and not string or timestamps. Whenever you manipulate dates or time, you need to import datetime function.\n",
    "\n",
    "The datetime classes in Python are categorized into main 5 classes.\n",
    "* date – Manipulate just date ( Month, day, year)\n",
    "* time – Time independent of the day (Hour, minute, second, microsecond)\n",
    "* datetime – Combination of time and date (Month, day, year, hour, second, microsecond)\n",
    "* timedelta— A duration of time used for manipulating dates\n",
    "\n",
    "\n",
    "### We Learn The Following \n",
    "\n",
    "* How to Use Date & DateTime Class\n",
    "* Print Date using date.today()\n",
    "* Python Current Date and Time: now() today()\n",
    "* How to Format Date and Time Output with Strftime()\n",
    "* How to use Timedelta Objects\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Printing Today, Date Components,Weekdays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Date Components  :-  30 8 2018\n",
      "Today's weekdays  :-  3\n"
     ]
    }
   ],
   "source": [
    "from datetime import date\n",
    "from datetime import time\n",
    "from datetime import datetime\n",
    "today = date.today()\n",
    "print(\"Today's Date is :- \", today)\n",
    "print(\"Date Components  :- \", today.day, today.month, today.year)\n",
    "print(\"Today's weekdays  :- \", today.weekday())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Aliasing or Renaming using as keyword"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:07:02.872806Z",
     "start_time": "2018-05-30T07:07:02.844739Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-08-30 17:30:33.032000\n"
     ]
    }
   ],
   "source": [
    "import datetime as dt\n",
    "print(dt.datetime.now())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## from Selected module  import Statement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T17:29:58.939364Z",
     "start_time": "2018-05-29T17:29:58.930846Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-08-30 17:32:21.678000\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(datetime.now())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Importing Everything from an module using `*`\n",
    "\n",
    "The from...import * Statement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T17:38:44.091153Z",
     "start_time": "2018-05-29T17:38:44.084039Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.141592653589793\n"
     ]
    }
   ],
   "source": [
    "from math import *\n",
    "print(pi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python Current Date and Time: now() today()\n",
    "* It gives date along with time in hours, minutes, seconds and milliseconds.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Current Date And Time is :-  2018-08-30 17:30:41.682000\n",
      "The Current Time is :-  17:30:41.682000\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "today= datetime.now()\n",
    "print(\"The Current Date And Time is :- \", today)   # Prints Date Along With Time.\n",
    "\n",
    "t= datetime.time(datetime.now())\n",
    "print(\"The Current Time is :- \", t)   # Prints time from datetime."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Today is day number 3\n",
      "which is a thursday\n"
     ]
    }
   ],
   "source": [
    "from datetime import date\n",
    "from datetime import time\n",
    "from datetime import datetime\n",
    "def main():\n",
    "    ##DATETIME OBJECTS\n",
    "    #Get today's date from datetime class\n",
    "    today=datetime.now()\n",
    "    #print (today)\n",
    "    # Get the current time\n",
    "    #t = datetime.time(datetime.now())\n",
    "    #print \"The current time is\", t\n",
    "    #weekday returns 0 (monday) through 6 (sunday)\n",
    "    wd=date.weekday(today)\n",
    "    #Days start at 0 for monday\n",
    "    days= [\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\",\"saturday\",\"sunday\"]\n",
    "    print(\"Today is day number %d\" % wd)\n",
    "    print(\"which is a \" + days[wd])\n",
    "\n",
    "if __name__== \"__main__\":\n",
    "    main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "9999\n"
     ]
    }
   ],
   "source": [
    "import datetime as dt\n",
    "\n",
    "print(dt.MINYEAR)\n",
    "\n",
    "print(dt.MAXYEAR)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T02:15:46.170834Z",
     "start_time": "2018-05-30T02:15:46.139942Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2018-10-10\n",
      "23:30:50\n",
      "2018-10-10 23:30:50\n",
      "23\n",
      "30\n",
      "50\n",
      "1999-02-10\n",
      "2011-01-11\n",
      "2018-08-30\n",
      "2018-05-30\n"
     ]
    }
   ],
   "source": [
    "my_date = dt.date(2018, 10, 10)\n",
    "\n",
    "my_time = dt.time(23, 30, 50)\n",
    "\n",
    "my_datetime = dt.datetime(2018, 10, 10, 23, 30, 50)\n",
    "\n",
    "print(my_date)\n",
    "\n",
    "print(my_time)\n",
    "\n",
    "print(my_datetime)\n",
    "\n",
    "print(my_time.hour)\n",
    "\n",
    "print(my_time.minute)\n",
    "\n",
    "print(my_time.second)\n",
    "\n",
    "print(dt.date(1999,2,10))\n",
    "\n",
    "from datetime import date\n",
    "\n",
    "print(date(2011, 1, 11))\n",
    "print(date.today())\n",
    "\n",
    "x = date(2018, 5, 30)\n",
    "\n",
    "print(x)\n",
    "\n",
    "print(x.year)\n",
    "\n",
    "print(x.month)\n",
    "\n",
    "print(x.day)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to Format Date and Time Output with Strftime()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thu Aug 30 17:20:00 2018\n",
      "08/30/18\n",
      "17:20:00\n",
      "05:20:00 PM\n",
      "17:20\n",
      "05:20\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "now= datetime.now() #get the current date and time\n",
    "\n",
    "#%c - local date and time, %x-local's date, %X- local's time\n",
    "print(now.strftime(\"%c\"))\n",
    "\n",
    "print(now.strftime(\"%x\"))\n",
    "\n",
    "print(now.strftime(\"%X\"))\n",
    "\n",
    "##### Time Formatting ####\n",
    "\n",
    "#%I/%H - 12/24 Hour, %M - minute, %S - second, %p - local's AM/PM\n",
    "\n",
    "print(now.strftime(\"%I:%M:%S %p\")) # 12-Hour:Minute:Second:AM\n",
    "\n",
    "print(now.strftime(\"%H:%M\")) # 24-Hour:Minute\n",
    "\n",
    "print(now.strftime(\"%I:%M\")) # 24-Hour:Minute"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to use Timedelta Objects\n",
    "\n",
    "* With timedelta objects, you can estimate the time for both future and the past. In other words, it is a timespan to predict any special day, date or time.\n",
    "* Remember this function is not for printing out the time or date, but something to CALCULATE about the future or past."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "365 days, 8:15:00\n",
      "today is: 2018-08-30 17:25:07.072000\n",
      "one year from now it will be:2019-08-30 17:25:07.072000\n"
     ]
    }
   ],
   "source": [
    "# Example file for working with timedelta objects\n",
    "from datetime import date\n",
    "from datetime import time\n",
    "from datetime import datetime\n",
    "from datetime import timedelta\n",
    "\n",
    "# construct a basic timedelta and print it\n",
    "print (timedelta(days=365, hours=8, minutes=15))\n",
    "\n",
    "# print today's date\n",
    "print (\"today is: \" + str(datetime.now()))\n",
    "\n",
    "# print today's date one year from now\n",
    "print (\"one year from now it will be:\" + str(datetime.now() + timedelta(days=365)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T17:36:47.767345Z",
     "start_time": "2018-05-29T17:36:47.756170Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.141592653589793\n",
      "2.718281828459045\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "print(math.pi)\n",
    "print(math.e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using help() and dir()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T03:07:36.071790Z",
     "start_time": "2018-05-30T03:07:36.051485Z"
    }
   },
   "outputs": [],
   "source": [
    "# dir(datetime)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T03:07:39.053889Z",
     "start_time": "2018-05-30T03:07:39.010973Z"
    }
   },
   "outputs": [],
   "source": [
    "# help(datetime)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some Important Modules in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### time module"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:19:33.849822Z",
     "start_time": "2018-05-30T07:19:33.845812Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1535630695.324\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "print(time.time())\n",
    "\n",
    "# Unix timestamp - number of seconds from the begining of time(epoch)\n",
    "# 1st Jan, 1970 @ 00:00:00"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:23:22.409144Z",
     "start_time": "2018-05-30T07:23:22.404631Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wed May 30 12:49:33 2018\n"
     ]
    }
   ],
   "source": [
    "# see time, sec to original format\n",
    "\n",
    "print(time.ctime(1527664773.8468134))\n",
    "\n",
    "# ctime(sec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T02:56:02.425997Z",
     "start_time": "2018-05-30T02:56:02.410368Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wed May 30 08:26:02 2018\n"
     ]
    }
   ],
   "source": [
    "#ask time\n",
    "\n",
    "print(time.asctime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:24:56.901774Z",
     "start_time": "2018-05-30T07:24:56.895258Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time.struct_time(tm_year=2018, tm_mon=5, tm_mday=30, tm_hour=7, tm_min=24, tm_sec=56, tm_wday=2, tm_yday=150, tm_isdst=0)\n"
     ]
    }
   ],
   "source": [
    "print(time.gmtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T02:57:55.028412Z",
     "start_time": "2018-05-30T02:57:55.015963Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wed May 30 02:57:55 2018\n"
     ]
    }
   ],
   "source": [
    "# Formatting the gmtime\n",
    "\n",
    "print(time.asctime(time.gmtime()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:27:18.334641Z",
     "start_time": "2018-05-30T07:27:18.330666Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time.struct_time(tm_year=2018, tm_mon=5, tm_mday=30, tm_hour=12, tm_min=57, tm_sec=18, tm_wday=2, tm_yday=150, tm_isdst=0)\n"
     ]
    }
   ],
   "source": [
    "print(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:31:17.188387Z",
     "start_time": "2018-05-30T07:31:17.181869Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Local current time : Wed May 30 13:01:17 2018\n"
     ]
    }
   ],
   "source": [
    "# formatted time\n",
    "\n",
    "import time, datetime\n",
    "\n",
    "localtime = time.asctime(time.localtime())\n",
    "\n",
    "print (\"Local current time :\", localtime)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T02:08:07.348973Z",
     "start_time": "2018-05-30T02:08:07.344459Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wednesday, May 30, 2018\n"
     ]
    }
   ],
   "source": [
    "# default format: yyyy-mm-dd\n",
    "\n",
    "# formatted date -> Day-Name(%A), Month-Name(%B), Day(%d), Year(%Y)\n",
    "\n",
    "print(x.strftime(\"%A, %B %d, %Y\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T18:03:58.385934Z",
     "start_time": "2018-05-29T18:03:58.367897Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-02\n",
      "0001-01-01\n",
      "9999-12-31\n"
     ]
    }
   ],
   "source": [
    "print(date.fromtimestamp(123123))\n",
    "\n",
    "print(date.min)\n",
    "\n",
    "print(date.max)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Maths module\n",
    "* It provides access to the mathematical functions defined by the C standard."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Math module\n",
    "\"\"\"\n",
    "ceil(x)\tReturns the smallest integer greater than or equal to x.\n",
    "copysign(x, y)\tReturns x with the sign of y\n",
    "fabs(x)\tReturns the absolute value of x\n",
    "factorial(x)\tReturns the factorial of x\n",
    "floor(x)\tReturns the largest integer less than or equal to x\n",
    "fmod(x, y)\tReturns the remainder when x is divided by y\n",
    "frexp(x)\tReturns the mantissa and exponent of x as the pair (m, e)\n",
    "fsum(iterable)\tReturns an accurate floating point sum of values in the iterable\n",
    "isfinite(x)\tReturns True if x is neither an infinity nor a NaN (Not a Number)\n",
    "isinf(x)\tReturns True if x is a positive or negative infinity\n",
    "isnan(x)\tReturns True if x is a NaN\n",
    "ldexp(x, i)\tReturns x * (2**i)\n",
    "modf(x)\tReturns the fractional and integer parts of x\n",
    "trunc(x)\tReturns the truncated integer value of x\n",
    "exp(x)\tReturns e**x\n",
    "expm1(x)\tReturns e**x - 1\n",
    "log(x[, base])\tReturns the logarithm of x to the base (defaults to e)\n",
    "log1p(x)\tReturns the natural logarithm of 1+x\n",
    "log2(x)\tReturns the base-2 logarithm of x\n",
    "log10(x)\tReturns the base-10 logarithm of x\n",
    "pow(x, y)\tReturns x raised to the power y\n",
    "sqrt(x)\tReturns the square root of x\n",
    "acos(x)\tReturns the arc cosine of x\n",
    "asin(x)\tReturns the arc sine of x\n",
    "atan(x)\tReturns the arc tangent of x\n",
    "atan2(y, x)\tReturns atan(y / x)\n",
    "cos(x)\tReturns the cosine of x\n",
    "hypot(x, y)\tReturns the Euclidean norm, sqrt(x*x + y*y)\n",
    "sin(x)\tReturns the sine of x\n",
    "tan(x)\tReturns the tangent of x\n",
    "degrees(x)\tConverts angle x from radians to degrees\n",
    "radians(x)\tConverts angle x from degrees to radians\n",
    "acosh(x)\tReturns the inverse hyperbolic cosine of x\n",
    "asinh(x)\tReturns the inverse hyperbolic sine of x\n",
    "atanh(x)\tReturns the inverse hyperbolic tangent of x\n",
    "cosh(x)\tReturns the hyperbolic cosine of x\n",
    "sinh(x)\tReturns the hyperbolic cosine of x\n",
    "tanh(x)\tReturns the hyperbolic tangent of x\n",
    "erf(x)\tReturns the error function at x\n",
    "erfc(x)\tReturns the complementary error function at x\n",
    "gamma(x)\tReturns the Gamma function at x\n",
    "lgamma(x)\tReturns the natural logarithm of the absolute value of the Gamma function at x\n",
    "pi\tMathematical constant, the ratio of circumference of a circle to it's diameter (3.14159...)\n",
    "e\tmathematical constant e (2.71828...)\n",
    "\"\"\"\n",
    "\n",
    "import math\n",
    "print(math.ceil(4))\n",
    "print(math.ceil(4.5))\n",
    "print(math.fabs(-3))\n",
    "print(math.factorial(3))\n",
    "print(math.floor(3.5))\n",
    "print(math.fsum([0.14,0.1,0.1])) #Floating sum with precision\n",
    "print(math.gcd(4,8))\n",
    "print(math.exp(3))\n",
    "print(math.log(8,2))\n",
    "print(math.pow(2,3))\n",
    "print(math.cos(0))\n",
    "print(math.sin(0))\n",
    "print(math.tan(0))\n",
    "print(math.acos(0))\n",
    "print(math.asin(0))\n",
    "print(math.atan(0))\n",
    "print(math.pi)\n",
    "print(math.e)\n",
    "print(math.tau)\n",
    "print(math.inf)\n",
    "print(math.nan)\n",
    "f=math.nan\n",
    "print(float(\"inf\")-float(\"inf\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T07:58:24.371424Z",
     "start_time": "2018-05-30T07:58:24.364406Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "124\n",
      "123\n",
      "720\n",
      "2.0\n"
     ]
    }
   ],
   "source": [
    "import math as m\n",
    "\n",
    "print(m.ceil(123.23))\n",
    "\n",
    "print(m.floor(123.23))\n",
    "\n",
    "\n",
    "print(m.factorial(6))\n",
    "\n",
    "print(m.sqrt(4))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T18:10:53.807147Z",
     "start_time": "2018-05-29T18:10:53.797438Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.283185307179586\n",
      "inf\n",
      "nan\n"
     ]
    }
   ],
   "source": [
    "print(m.tau)\n",
    "\n",
    "print(m.inf)\n",
    "\n",
    "print(m.nan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T18:37:35.961746Z",
     "start_time": "2018-05-29T18:37:35.949713Z"
    }
   },
   "outputs": [],
   "source": [
    "# help(math)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Random module\n",
    "\n",
    "* When to use it ..?? -->  We want the computer to pick a random number in a given range"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T08:09:49.041346Z",
     "start_time": "2018-05-30T08:09:49.037331Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7178156228706927\n"
     ]
    }
   ],
   "source": [
    "from random import *\n",
    "\n",
    "print(random())\n",
    "\n",
    "# 0 and 1 (not inclusive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Random functions\n",
    "* The Random module contains some very useful functions\n",
    "\n",
    "### randint(a,b)\n",
    "\n",
    "* If we wanted a random integer, we can use the randint function\n",
    "\n",
    "* Randint accepts two parameters: a lowest and a highest number.\n",
    "* a and b inclusive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T08:10:48.073232Z",
     "start_time": "2018-05-30T08:10:48.069218Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\"\"\"\n",
    "Generate integers between 1,5.\n",
    "The first value should be less than the second.\n",
    "\"\"\"\n",
    "import random\n",
    "print(random.randint(0, 5))\n",
    "\n",
    "# 0 and 5 are inclusive (Included)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4916\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "Generate integers between 1000,9999.\n",
    "The first value should be less than the second.\n",
    "\"\"\"\n",
    "import random\n",
    "from random import *\n",
    "print(randint(1000, 9999))\n",
    "\n",
    "# 1000 and 9999 (inclusive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### uniform(a, b) \n",
    "* Return a random floating point number between a and b inclusive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-29T18:33:37.867771Z",
     "start_time": "2018-05-29T18:33:37.851910Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.234791377636977\n"
     ]
    }
   ],
   "source": [
    "print(uniform(1, 10))\n",
    "\n",
    "# float between 1 and 10 (not inclusive)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Choice\n",
    "\n",
    "* it Generates a random value from the sequence sequence.\n",
    "\n",
    "\n",
    "* The choice function can often be used for choosing a random element from a list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-30T08:12:18.949643Z",
     "start_time": "2018-05-30T08:12:18.944629Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "482\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "myList = [2, 109, False, 10, \"Mukesh\", 482, \"Acadview\"]\n",
    "print(random.choice(myList))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "from random import *\n",
    "lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']\n",
    "\n",
    "print(choice(lst))\n",
    "\n",
    "# return a random item from a list or tuple"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Shuffle\n",
    "* The shuffle function, shuffles the elements in list in place, so they are in a\n",
    "random order."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List Before Shuffling is  [0, 1, 2, 3, 4]\n",
      "List after Shuffling is  [4, 1, 3, 2, 0]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "s=list(range(5))\n",
    "print(\"List Before Shuffling is \", s)\n",
    "random.shuffle(s) # << shuffle before print or assignment\n",
    "print(\"List after Shuffling is \",s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Randrange\n",
    "\n",
    "* Generate a randomly selected element from range(start, stop, step)\n",
    "\n",
    "* Syntax :- random.randrange(start, stop[, step])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n",
      "100\n",
      "70\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "for i in range(3):\n",
    "    print(random.randrange(0, 101, 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sample(population, k)\t\n",
    "* Return a k length list of unique elements chosen from the population sequence"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n",
      "[2, 1, 6, 9, 14]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "c = list(range(0, 15))\n",
    "print(c)\n",
    "\n",
    "print(random.sample(c, 5))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Webbrowser module \n",
    "\n",
    "* The webbrowser module in Python provides an interface to display Web-based documents.\n",
    "* calling the `open()` function from this module will do the right thing. \n",
    "\n",
    "* Using `webbrowser.open_new_tab` A new browser tab will open with the search term in googles search field."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter Your Google search:Djpunjab.com\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "webbrowser.open_new(url)\n",
    "    Open url in a new window of the default browser, if possible, otherwise,\n",
    "    open url in the only browser window.\n",
    "\n",
    "webbrowser.open_new_tab(url)\n",
    "    Open url in a new page (“tab”) of the default browser, if possible, \n",
    "    otherwise equivalent to open_new().\n",
    "\"\"\"\n",
    "\n",
    "import webbrowser\n",
    "google = input('Enter Your Google search:')\n",
    "webbrowser.open_new_tab('http://www.google.com/search?btnG=1&q=%s' % google)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Calender Module\n",
    "* Displaying Month   :- The built-in function month() inside the Calender module takes in the year and the month and displays the calendar for that month of the year.\n",
    "\n",
    "\n",
    "* Displaying year :- The built-in function calender() inside the module takes in the year and displays the calendar for that year.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   November 2018\n",
      "Mo Tu We Th Fr Sa Su\n",
      "          1  2  3  4\n",
      " 5  6  7  8  9 10 11\n",
      "12 13 14 15 16 17 18\n",
      "19 20 21 22 23 24 25\n",
      "26 27 28 29 30\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import calendar\n",
    "\n",
    "year = 2018\n",
    "month = 11\n",
    "\n",
    "# display the calendar\n",
    "print(calendar.month(year, month))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                  2018\n",
      "\n",
      "      January                   February                   March\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      " 1  2  3  4  5  6  7                1  2  3  4                1  2  3  4\n",
      " 8  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11\n",
      "15 16 17 18 19 20 21      12 13 14 15 16 17 18      12 13 14 15 16 17 18\n",
      "22 23 24 25 26 27 28      19 20 21 22 23 24 25      19 20 21 22 23 24 25\n",
      "29 30 31                  26 27 28                  26 27 28 29 30 31\n",
      "\n",
      "       April                      May                       June\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      "                   1          1  2  3  4  5  6                   1  2  3\n",
      " 2  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 10\n",
      " 9 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17\n",
      "16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24\n",
      "23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30\n",
      "30\n",
      "\n",
      "        July                     August                  September\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      "                   1             1  2  3  4  5                      1  2\n",
      " 2  3  4  5  6  7  8       6  7  8  9 10 11 12       3  4  5  6  7  8  9\n",
      " 9 10 11 12 13 14 15      13 14 15 16 17 18 19      10 11 12 13 14 15 16\n",
      "16 17 18 19 20 21 22      20 21 22 23 24 25 26      17 18 19 20 21 22 23\n",
      "23 24 25 26 27 28 29      27 28 29 30 31            24 25 26 27 28 29 30\n",
      "30 31\n",
      "\n",
      "      October                   November                  December\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      " 1  2  3  4  5  6  7                1  2  3  4                      1  2\n",
      " 8  9 10 11 12 13 14       5  6  7  8  9 10 11       3  4  5  6  7  8  9\n",
      "15 16 17 18 19 20 21      12 13 14 15 16 17 18      10 11 12 13 14 15 16\n",
      "22 23 24 25 26 27 28      19 20 21 22 23 24 25      17 18 19 20 21 22 23\n",
      "29 30 31                  26 27 28 29 30            24 25 26 27 28 29 30\n",
      "                                                    31\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import calendar\n",
    "from calendar import *\n",
    "\n",
    "year = 2018\n",
    "\n",
    "\n",
    "# display the calendar for year \n",
    "print(calendar(year))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Operations on calendar :\n",
    "\n",
    "1. calendar(year, w, l, c) :- This function displays the year, width of characters, no. of lines per week and column separations.\n",
    "\n",
    "2. firstweekday() :- This function returns the first week day number. By default 0 (Monday)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The calender of year 2012 is : \n",
      "                                  2012\n",
      "\n",
      "      January                   February                   March\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      "                   1             1  2  3  4  5                1  2  3  4\n",
      " 2  3  4  5  6  7  8       6  7  8  9 10 11 12       5  6  7  8  9 10 11\n",
      " 9 10 11 12 13 14 15      13 14 15 16 17 18 19      12 13 14 15 16 17 18\n",
      "16 17 18 19 20 21 22      20 21 22 23 24 25 26      19 20 21 22 23 24 25\n",
      "23 24 25 26 27 28 29      27 28 29                  26 27 28 29 30 31\n",
      "30 31\n",
      "\n",
      "       April                      May                       June\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      "                   1          1  2  3  4  5  6                   1  2  3\n",
      " 2  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 10\n",
      " 9 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17\n",
      "16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24\n",
      "23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30\n",
      "30\n",
      "\n",
      "        July                     August                  September\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      "                   1             1  2  3  4  5                      1  2\n",
      " 2  3  4  5  6  7  8       6  7  8  9 10 11 12       3  4  5  6  7  8  9\n",
      " 9 10 11 12 13 14 15      13 14 15 16 17 18 19      10 11 12 13 14 15 16\n",
      "16 17 18 19 20 21 22      20 21 22 23 24 25 26      17 18 19 20 21 22 23\n",
      "23 24 25 26 27 28 29      27 28 29 30 31            24 25 26 27 28 29 30\n",
      "30 31\n",
      "\n",
      "      October                   November                  December\n",
      "Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su\n",
      " 1  2  3  4  5  6  7                1  2  3  4                      1  2\n",
      " 8  9 10 11 12 13 14       5  6  7  8  9 10 11       3  4  5  6  7  8  9\n",
      "15 16 17 18 19 20 21      12 13 14 15 16 17 18      10 11 12 13 14 15 16\n",
      "22 23 24 25 26 27 28      19 20 21 22 23 24 25      17 18 19 20 21 22 23\n",
      "29 30 31                  26 27 28 29 30            24 25 26 27 28 29 30\n",
      "                                                    31\n",
      "\n",
      "The starting day number in calendar is : 0\n"
     ]
    }
   ],
   "source": [
    "# Python code to demonstrate the working of\n",
    "# calendar() and firstweeksday()\n",
    " \n",
    "# importing calendar module for calendar operations\n",
    "import calendar\n",
    " \n",
    "# using calender to print calendar of year\n",
    "# prints calendar of 2012\n",
    "print (\"The calender of year 2012 is : \")\n",
    "print (calendar.calendar(2012,2,1,6))\n",
    " \n",
    "#using firstweekday() to print starting day number\n",
    "print (\"The starting day number in calendar is : \",end=\"\")\n",
    "print (calendar.firstweekday())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3. isleap (year) :- This function checks if year mentioned in argument is leap or not.\n",
    "\n",
    "#### 4. leapdays (year1, year2) :- This function returns the number of leap days between the specified years in arguments."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The year is leap\n",
      "The leap days between 1950 and 2000 are : 12\n"
     ]
    }
   ],
   "source": [
    "# Python code to demonstrate the working of\n",
    "# isleap() and leapdays()\n",
    " \n",
    "# importing calendar module for calendar operations\n",
    "import calendar\n",
    " \n",
    "# using isleap() to check if year is leap or not\n",
    "if (calendar.isleap(2008)):\n",
    "       print (\"The year is leap\")\n",
    "else : print (\"The year is not leap\")\n",
    " \n",
    "#using leapdays() to print leap days between years \n",
    "print (\"The leap days between 1950 and 2000 are : \",end=\"\")\n",
    "print (calendar.leapdays(1950, 2000))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 5. month (year, month, w, l) :- This function prints the month of a specific year mentioned in arguments. It takes 4 arguments, year, month, width of characters and no. of lines taken by a week."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The month 5th of 2016 is :\n",
      "      May 2016\n",
      "Mo Tu We Th Fr Sa Su\n",
      "                   1\n",
      " 2  3  4  5  6  7  8\n",
      " 9 10 11 12 13 14 15\n",
      "16 17 18 19 20 21 22\n",
      "23 24 25 26 27 28 29\n",
      "30 31\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Python code to demonstrate the working of\n",
    "# month()\n",
    " \n",
    "# importing calendar module for calendar operations\n",
    "import calendar\n",
    " \n",
    "# using month() to display month of specific year\n",
    "print (\"The month 5th of 2016 is :\")\n",
    "print (calendar.month(2016,5,2,1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
